<?php

class commentTutorial extends Model
{

	function getComment($id)
	{
		$gcomment = $this->db->getAll("SELECT tutorial.title,
				ct.comment_id, 
				ct.stud_no, 
				ct.date,
				ct.comment,
				organization.name Org,
				user.lastname, 
				user.firstname,
				user.middlename
			FROM tutorial,organization, commenttutorial ct, user
			WHERE tutorial.org_id = organization.org_id 
			AND ct.stud_no = user.stud_no
			AND ct.topic_id = tutorial.topic_id
			AND tutorial.topic_id = ?
			ORDER BY ct.date ASC",
			array($id));
		return $gcomment;
	}

	function insertComment ( $topic_id, $stud_no, $date, $comment )
	{
		$icomment = $this->db->execute("INSERT INTO commenttutorial( topic_id,
			stud_no,
			date,
			comment )
			VALUES ( ?, ?, ?, ? )", 
			array( $topic_id, $stud_no, $date, $comment )
		);
		return $icomment;
	}

	function updateComment( $article_id, $stud_no, $date, $comment, $comment_id ) 
	{
		$ucomment = $this->db->execute("UPDATE commenttutorial
			SET topic_id = ?,
			stud_no = ?,
			date = ?,
			comment = ?			
			WHERE comment_id = ?",
			array( $article_id, $stud_no, $date, $comment, $comment_id  )
		);
		return $ucomment;
	}

	function deleteComment ( $comment_id )
	{
		$dphoto = $this->db->execute("DELETE FROM commenttutorial where comment_id = ?" ,
			array( $comment_id  ) 
		);
	}
}